@@ -174,8 +174,8 @@ module Agents |
||
174 | 174 |
new_files.sort_by { |filename| |
175 | 175 |
found_entries[filename] |
176 | 176 |
}.each { |filename| |
177 |
- create_event :payload => { |
|
178 |
- 'url' => "#{base_uri}#{filename}", |
|
177 |
+ create_event payload: { |
|
178 |
+ 'url' => (base_uri + uri_path_escape(filename)).to_s, |
|
179 | 179 |
'filename' => filename, |
180 | 180 |
'timestamp' => found_entries[filename], |
181 | 181 |
} |
@@ -192,5 +192,13 @@ module Agents |
||
192 | 192 |
rescue |
193 | 193 |
false |
194 | 194 |
end |
195 |
+ |
|
196 |
+ def uri_path_escape(string) |
|
197 |
+ str = string.dup.force_encoding(Encoding::ASCII_8BIT) # string.b in Ruby >=2.0 |
|
198 |
+ str.gsub!(/([^A-Za-z0-9\-._~!$&()*+,=@]+)/) { |m| |
|
199 |
+ '%' + m.unpack('H2' * m.bytesize).join('%').upcase |
|
200 |
+ } |
|
201 |
+ str.force_encoding(Encoding::US_ASCII) |
|
202 |
+ end |
|
195 | 203 |
end |
196 | 204 |
end |
@@ -76,6 +76,12 @@ describe Agents::FtpsiteAgent do |
||
76 | 76 |
'timestamp' => '2014-04-02T10:00:00Z', |
77 | 77 |
} |
78 | 78 |
|
79 |
+ Event.last.payload.should == { |
|
80 |
+ 'url' => 'ftp://ftp.example.org/pub/releases/example%20latest.tar.gz', |
|
81 |
+ 'filename' => 'example latest.tar.gz', |
|
82 |
+ 'timestamp' => '2014-04-02T10:00:01Z', |
|
83 |
+ } |
|
84 |
+ |
|
79 | 85 |
lambda { @checker.check }.should_not change { Event.count } |
80 | 86 |
end |
81 | 87 |
end |